package com.shujia;

import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class RedisTest {
    Jedis jedis;


    // @Before 表示在@Test之前进行执行
    @Before
    public void getJedis(){
        jedis = new Jedis("192.168.163.100", 6379);
    }



    @Test
    public void setString() {
        Jedis jedis = new Jedis("192.168.163.100", 6379);
        jedis.set("apiString", "jedis Connect");
    }

    @Test
    public void keys() {
        Jedis jedis = new Jedis("192.168.163.100", 6379);
        Set<String> keys = jedis.keys("*");
        System.out.println(keys);
        jedis.close();
    }

    @Test
    public void mSet() {
        Jedis jedis = new Jedis("192.168.163.100", 6379);
        jedis.mset("apiKey1", "value1", "apiKey2", "value2");
        jedis.close();
    }


    @Test
    public void hash(){

        jedis.hset("hash1","userName","lisi");
        System.out.println(jedis.hget("hash1","userName"));

        Map<String,String> map = new HashMap<String,String>();
        map.put("clazz","bigdata26");
        map.put("name","huazi");
        map.put("age","23");
        jedis.hmset("hash2",map);


        List<String> result = jedis.hmget("hash2", "clazz","name");
        for (String element : result) {
            System.out.println(element);
        }
    }


}
